#!/bin/bash
#set -ex
IMAGES=$(find images -type f -name Dockerfile* | sed 's|images/||g' | sed 's|/Dockerfile[a-z0-9.]*||g' | sort | uniq | xargs)

IMAGENAME=$1
TAG=$2
REGISTRY=$3

usage() {
    echo "Push specified OAI image to a specified registry.
    
usage: $(basename $0) [-h] [-f] [IMAGE_NAME TAG REGISTRY]
  -h|--help:        prints this help message
  
available images:
  $IMAGES"
    exit 1
}

while [[ $# < 3 ]]; do
    usage
done

login_registry() {
podman login $REGISTRY
}


push_image() {
IMAGEID=$(podman image ls | grep $IMAGENAME | grep $TAG | awk '{print $3}')
echo $IMAGEID
podman push $IMAGEID $REGISTRY
}

login_registry $REGISTRY
push_image $IMAGENAME $REGISTRY
